<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>登陆页面</title>
</head>
<body>
<?php 
	if(isset($_POST['dosubmit'])){
		$pdo = new PDO("mysql:host=localhost; dbname=php_study", "root", "root");

		$stmt = $pdo->prepare("select id,username,allow_1,allow_2,allow_3,allow_4 from user where username = ? and password = ?");

		$stmt -> execute(array($_POST['username'], $_POST['password']));

		//如果查出数据，说明这个用户是存在的，就让登陆
		if($stmt->rowCount() > 0){

			list($id, $username, $allow_1, $allow_2, $allow_3, $allow_4) = $stmt->fetch(PDO::FETCH_NUM);

			$time = time()+24*60*60;

			setCookie("uid", $uid, $time, "/");
			setCookie("username", $username, $time, "/");
			setCookie("allow_1", $allow_1, $time, "/");
			setCookie("allow_2", $allow_2, $time, "/");
			setCookie("allow_3", $allow_3, $time, "/");
			setCookie("allow_4", $allow_4, $time, "/");

			//设置一个登陆判断的的标记
			setCookie("isLogin", 1, $time, "/");


			header("location:04-index.php");

		}else{
			echo "登录失败！！！";
		}
		
	}


 ?>

	<h3 align="center">用户登陆</h3>
	<form action="08-login.php" method="post">
		<h5 align="center">
			username:
			<input type="text" name="username" value="" placeholder="username" required="required">
			<br>
		</h5>
		<h5 align="center">
			password:
			<input type="password" name="password" value="" placeholder="password" required="required">
			<br>
		</h5>
		<h5 align="center">
			<input type="submit" name="dosubmit" value="login">
			&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="reset" name="" value="reset">
		</h5>
	</form>
</body>
</html>


